import java.util.Objects;

/**
 * ClassName Person
 * Description TODO
 * Author Hexiao
 * Date 2018/8/20 17:14
 * Version 1.0
 **/
//TreeMap实现排序的两种方法
//    法一：继承Comparable接口，复写compareTo方法
public class Person implements Comparable {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &&
                Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {

        return Objects.hash(name, age);
    }

    @Override
    public int compareTo(Object o) {
        Person person=(Person)o;
        if (this.age-person.age==0){
            return this.name.compareTo(person.name);
        }
        return 0;
    }
}